package com.xyw.code.bus.center.rest;

import com.alibaba.fastjson.JSONObject;
import com.xyw.code.bus.center.event.MQErrorReceiver;
import com.xyw.code.bus.center.event.MessageSendAsync;
import com.xyw.code.bus.center.service.ICommonMessageService;
import com.xyw.code.bus.common.entity.form.SendMessageForm;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created with IntelliJ IDEA.
 * User: xuyiwei
 * Date: 2020/2/18
 * Time: 下午9:25
 * Email: 1328312923@qq.com
 * Description: No Description
 **/

@RestController
@RequestMapping("/")
@Slf4j
public class SendMessageController {

    @Autowired
    private MessageSendAsync messageSendAsync;

    @Autowired
    private ICommonMessageService commonMessageService;

   /**
     * 测试发送消息并异步接收响应
     */
    @PostMapping("/sendMessage")
    public void sendMessage(@RequestBody SendMessageForm sendMessageForm) {
        messageSendAsync.sendMsg(sendMessageForm.getExchange(),sendMessageForm.getRouteKey(),sendMessageForm.getMessage(),null);
    }

    /**
     * 处理失败的消息
     */
    @PostMapping("/dealFail")
    public void dealFail(@RequestBody SendMessageForm sendMessageForm) {
        commonMessageService.dealFailMessage(sendMessageForm);
    }
}